<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('finance_branch_bills', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('customer_bill_id')->nullable()->comment('客户总账单id');
            $table->unsignedInteger('department_id')->nullable()->comment('客服2级部门id');
            $table->string('department_name')->nullable()->comment('部门名称');
            $table->char('bill_date',16)->nullable()->comment('账单日期:年月');
            $table->tinyInteger('bill_status')->default(0)->comment('账单状态：默认0待填报，1待分部主管审核，2待财务审核，3待结算，4已结清');
            $table->unsignedInteger('total_service_days')->nullable()->comment('服务天数');
            $table->unsignedInteger('total_consult')->nullable()->comment('总咨询量');
            $table->decimal('total_pay_branch',12,1)->nullable()->comment('应付分部');
            $table->text('bill_imgs')->nullable()->comment('账单附属图片');

            $table->decimal('actual_pay_branch',12,1)->nullable()->comment('实付分部');
            $table->decimal('not_pay_amount',12,1)->nullable()->comment('未付');
            $table->decimal('add_amount',12,1)->nullable()->comment('增收');
            $table->decimal('extra_refund',12,1)->nullable()->comment('补退');
            $table->decimal('extra_receive',12,1)->nullable()->comment('补收');
            $table->decimal('waste_amount',12,1)->nullable()->comment('损耗');
            $table->tinyInteger('clear_status')->default(0)->comment('默认0未结清，1已结清');
            $table->tinyInteger('is_reassign_bill')->default(0)->comment('是否重新分配店铺订单：默认0否，1是');

            $table->string('wx_group')->nullable()->comment('微信群');
            $table->date('bill_period_start')->nullable()->comment('账单开始日期');
            $table->date('bill_period_end')->nullable()->comment('账单结束日期');
            $table->tinyInteger('bill_type')->default(0)->comment('账单类型');
            $table->char('bill_month',64)->nullable()->comment('账单月份');
            $table->integer('customer_id')->nullable()->comment('客户id');
            $table->char('company_name',64)->nullable()->comment('公司名称');

            $table->timestamps();
        });
        \DB::statement("ALTER TABLE `finance_branch_bills` comment '分部账单'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('finance_branch_bills');
    }
};
